/* 
 * File:   Solver.h
 * Author: gizmo
 *
 * Created on September 26, 2010, 2:26 PM
 */

#ifndef SOLVER_H
#define	SOLVER_H


#include "Graph.h"
#include "State.h"
#include "Stack.h"

using namespace std;

#define MSG_CHECK_INTERVAL     100  // after how many iterations messages should be checked

#define MSG_WORK_REQUEST       1    // process has no states, wants work
#define MSG_NO_WORK_RESPONSE   2    // process is not willing to send any states to requesting process
#define MSG_WORK_RESPONSE      3    // process is sending states to requesting process
#define MSG_WHITE_TOKEN        4    // white ending token
#define MSG_BLACK_TOKEN        5    // black ending token
#define MSG_TERMINATE          6    // if recieved, process terminates counting
#define MSG_BEST_SOLUTION      7    // best solution found with particular process
#define MSG_SIGNAL_LENGTH      1    // all MSGs except WORK_RESPONSE are considered as signal and carry no data

#define COLOR_WHITE            1    // color of process
#define COLOR_BLACK            2    // color of process

/*
 * Solver class should contain whole algorithm and decision making incl.
 * stack of State instances. In the end a bestSolution should be found.
 */
class Solver {
public:
    Solver();
    Solver(const Solver& orig);
    virtual ~Solver();

    void init(Graph * gGraph, int rank, int total);
    
    void solve();
    State & getBestSolution();

    void startClock();
    void endClock();
    double getRunningTime() const;

private:
    Graph * graph;
    State bestSolution;
    Stack myStack;
    double start, end;
    int process_rank;
    int processes;
    static const unsigned int BUFFER_SIZE = 600; // only stacks are sent - 2 processes, 30 nodes, 30*15=450

};

#endif	/* SOLVER_H */

